package com.daka.service.impl;

import com.daka.dao.AppVersionMapper;
import com.daka.entity.Version;
import com.daka.enumerate.CommonStatus;
import com.daka.service.AppVersionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @author beliveli on 2016/3/31 0031.
 */
@Service("appVersionService")
@SuppressWarnings("unused")
public class AppVersionServiceImpl implements AppVersionService {

    @Resource(name = "appVersionMapper")
    private AppVersionMapper appVersionMapper;

    public List<Version> select(Version version) {
        return appVersionMapper.select(version);
    }

    public List<Version> selectAll() {
        return appVersionMapper.selectAll();
    }

    public Version save(Version version) {

        int resultCount = 0;
        if (version.getVersionId() == 0) {
            version.setCreateTime(new Timestamp(new Date().getTime()));
            version.setStatus(CommonStatus.NORMAL.getStatusCode());
            resultCount = appVersionMapper.save(version);
        }

        if (resultCount == 0) {
            return null;
        }
        return version;
    }

    public int updateStatus(Integer status, Integer versionId) {
        return appVersionMapper.updateStatus(status,versionId);
    }

    public Version selectById(int versionId){
        return appVersionMapper.selectById(versionId);
    }
}
